<template>
  <div class="app">
    <h1 :style="{ opacity }">Vue真难，不想学了</h1>
    <button @click="$destroy()">不学了</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      opacity: 1,
      timer: null,
    };
  },

  mounted() {
    this.timer = setInterval(() => {
      console.log(Math.random());
      this.opacity -= 0.1;
      if (this.opacity <= 0) {
        this.opacity = 1;
      }
    }, 200);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
};
</script>

<style scoped>
.app {
  border: 3px solid #aaa;
}
</style>